package cn.itcast.mapper;

import cn.itcast.domain.Company;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * Company持久层接口
 */
public interface CompanyMappe {
    //查询所有
    @Select("select * from  st_company")
    List<Company> findAll();

    //添加功能
    @Insert(" insert into st_company (id, name, expiration_date,\n" +
            "        address, license_id, representative,\n" +
            "        phone, company_size, industry,\n" +
            "        remarks, state,\n" +
            "        city)\n" +
            "        values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{expirationDate,jdbcType=TIMESTAMP},\n" +
            "        #{address,jdbcType=VARCHAR}, #{licenseId,jdbcType=VARCHAR}, #{representative,jdbcType=VARCHAR},\n" +
            "        #{phone,jdbcType=VARCHAR}, #{companySize,jdbcType=VARCHAR}, #{industry,jdbcType=VARCHAR},\n" +
            "        #{remarks,jdbcType=VARCHAR}, #{state,jdbcType=INTEGER},\n" +
            "        #{city,jdbcType=VARCHAR})")
    void add(Company company);

    //查询功能,根据id
    @Select("select * from  st_company where id = #{id}")
    Company findById(String id);

    //修改功能
    @Update("update st_company\n" +
            "        set name = #{name,jdbcType=VARCHAR},\n" +
            "        expiration_date = #{expirationDate,jdbcType=TIMESTAMP},\n" +
            "        address = #{address,jdbcType=VARCHAR},\n" +
            "        license_id = #{licenseId,jdbcType=VARCHAR},\n" +
            "        representative = #{representative,jdbcType=VARCHAR},\n" +
            "        phone = #{phone,jdbcType=VARCHAR},\n" +
            "        company_size = #{companySize,jdbcType=VARCHAR},\n" +
            "        industry = #{industry,jdbcType=VARCHAR},\n" +
            "        remarks = #{remarks,jdbcType=VARCHAR},\n" +
            "        state = #{state,jdbcType=INTEGER},\n" +
            "        city = #{city,jdbcType=VARCHAR}\n" +
            "        where id = #{id,jdbcType=VARCHAR} " )
    void update(Company company);


    //批量删除
    void deleteByIds(String[] ids);

    //模糊查询
    @Select("SELECT * FROM st_company WHERE NAME LIKE CONCAT('%',#{val},'%') ")
    List<Company> findLikeName(String val);
}
